package main

import "fmt"

func sum1(s []int, c chan int) {
	resultSum := 0
	for _, v := range s {
		resultSum += v
	}
	c <- resultSum // 把 sum 发送到通道 c
}

func count2() {
	s := []int{7, 2, 8, -9, 4, 0}
	var r []int

	c := make(chan int, 2)
	go sum1(s[:len(s)/2], c)
	go sum1(s[len(s)/2:], c)

	for range cap(c) {
		r = append(r, <-c)
	}

	resultSum := 0
	for _, value := range r {
		fmt.Print( value, ",")
		resultSum += value
	}
	fmt.Println(resultSum)
}
